// JavaScript Document

// JavaScript Document

// counts the amount of courses
var courseCounter = 1;

// count of courses starting from
var initialCount = 0;


// deletes a course row
function deleteCourse(set){
	var deleterow = document.getElementById("kurs"+set);
	document.getElementById("kurstabelle").removeChild(deleterow);
	courseCounter = document.schulehinzufuegen.kursanzahl.value-1;
	setCourseCount(courseCounter);
}

// adds another line in table to insert a new course
function addCourse(set){
	if (initialCount != set){
		initialCount = set;
		courseCounter = set;
	}
	courseCounter++;
	var newrow=document.createElement("tr");
	newrow.setAttribute("id", "kurs"+courseCounter);
	document.getElementById("kurstabelle").appendChild(newrow);
	document.getElementById("kurs"+courseCounter).innerHTML = "<td bgcolor='#EDEEEF'><textarea name=kurstitel"+courseCounter+" id=kurstitel"+courseCounter+" ></textarea></td><td bgcolor='#CCCCCC'><textarea name=kurskurzbeschreibung"+courseCounter+" id=kurskurzbeschreibung"+courseCounter+"></textarea></td><td bgcolor='#F2F2EE'><input type='text' value='' name=wochenstunden"+courseCounter+" id=wochenstunden"+courseCounter+" maxlength='5' /></td><td bgcolor='#F2F2EE' align='center'><input type=text name=1kurswoche"+courseCounter+" id=1kurswoche"+courseCounter+" value=''  /></td><td bgcolor='#F2F2EE' align='center'><input type=text name=2kurswoche"+courseCounter+" id=2kurswoche"+courseCounter+"  value=''  /></td><td bgcolor='#F2F2EE' align='center'><input type=text name=3kurswoche"+courseCounter+" id=3kurswoche"+courseCounter+"  value=''  /></td><td bgcolor='#F2F2EE' align='center'><input type=text name=4kurswoche"+courseCounter+" id=4kurswoche"+courseCounter+"  value=''  /></td><td bgcolor='#F2F2EE' align='center'><input type=text name=weiterekurswoche"+courseCounter+" id=weiterekurswoche"+courseCounter+"  value=''  /></td><td bgcolor='#F2F2EE'><a href='javascript: deleteCourse("+courseCounter+");'>loeschen</a></td>";
	setCourseCount(courseCounter);
}

// set the amount of courses inserted
function setCourseCount(course_count){
	document.schulehinzufuegen.kursanzahl.value = course_count;
}

// set the amount of lodging inserted
function setLodgingCount(u_count){
	document.schulehinzufuegen.unterkunftanzahl.value = u_count;
}
// set the amount of pickups inserted
function setPickUpCount(p_count){
	document.schulehinzufuegen.pickupanzahl.value = p_count;
}
  
  // zaehlt mit wieviele Unterkünfte bereits eingegeben wurden
  var ucounter = 1;
  
  var uicounter = 0;
 
// deletes an Accommodation
function deleteAcco(set){
	var deleterow = document.getElementById("unterkunft"+set);
	document.getElementById("unterkunfttabelle").removeChild(deleterow);
	ucounter = document.schulehinzufuegen.unterkunftanzahl.value -1;
	setLodgingCount(ucounter);
}
 
// Fügt neue Reihe in Tabelle hinzu um weiteren Kurshinzufügen
function unterkunftHinzufuegen(set){
	if (uicounter != set){
		uicounter = set;
		ucounter = set;
	}
	ucounter++;
	var newrow=document.createElement("tr");
	newrow.setAttribute("id", "unterkunft"+ucounter);
	document.getElementById("unterkunfttabelle").appendChild(newrow);
	document.getElementById("unterkunft"+ucounter).innerHTML = "<td bgcolor=#CCCCCC><textarea name=utitel"+ucounter+" rows=1 id=utitel"+ucounter+"></textarea></td><td bgcolor=#CCCCCC><input type=text name=1woche"+ucounter+"  id=1woche"+ucounter+" /></td><td bgcolor=#CCCCCC><input type=text name=2woche"+ucounter+" id=2woche"+ucounter+" /></td><td bgcolor=#CCCCCC><input type=text name=3woche"+ucounter+" id=3woche"+ucounter+" /></td><td bgcolor=#CCCCCC><input type=text name=4woche"+ucounter+" id=4woche"+ucounter+" /></td><td bgcolor=#CCCCCC><input type=text name=weiterewoche"+ucounter+" id=weiterewoche"+ucounter+" /></td><td bgcolor='#F2F2EE'><a href='javascript: deleteAcco("+ucounter+");'>loeschen</a></td>";
	
	// set the amount of lodging inserted
	setLodgingCount(ucounter);
}


// deletes a PickUp Service
function deletePickUp(set){
	var deleterow = document.getElementById("pickupnr"+set);
	document.getElementById("pickuptabelle").removeChild(deleterow);
	pcounter = document.schulehinzufuegen.pickupanzahl.value -1;
	setPickUpCount(pcounter);
}

  // zaehlt mit wieviele pickups bereits eingegeben wurden
  var pcounter = 0;
  var picounter = 0;

 // Fügt neue Reihe in Tabelle hinzu um weiteren Kurshinzufügen
function addPickUp(set){
	if (picounter != set){
		picounter = set;
		pcounter = set;
	}
	pcounter++;
	var newrow=document.createElement("tr");
	newrow.setAttribute("id", "pickupnr"+pcounter);
	document.getElementById("pickuptabelle").appendChild(newrow);
	document.getElementById("pickupnr"+pcounter).innerHTML = '<tr id="pickupnr'+pcounter+'"><td bgcolor="#F2F2EE" align="center"><input type="text" name="pickup'+pcounter+'" id="pickup'+pcounter+'" /></td><td bgcolor="#F2F2EE" align="center"><input type="text" name="pickupprice'+pcounter+'" id="pickupprice'+pcounter+'" /></td><td bgcolor="#F2F2EE"><a href="javascript: deletePickUp('+pcounter+');">loeschen</a></td></tr>';
	
	// set the amount of lodging inserted
	setPickUpCount(pcounter);
}